package org.canaan.auth2.action;

import org.canaan.auth2.entity.User;
import org.canaan.auth2.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;

@RequestMapping("test")
@Controller
public class TestAction {
    private final Logger logger = LoggerFactory.getLogger(TestAction.class);
    @Autowired
    private UserService userService;
    
    TestAction(){
        logger.debug("init {} =========================",this.getClass());
    }
    
    @RequestMapping("/hello.data")
    @ResponseBody
    public String hello(){
        logger.debug("access test/hello.data");
        return "hello";
    }
    
    @RequestMapping("/getuser.data")
    @ResponseBody
    public String getUser(){
    	User user = (User) userService.loadUserByUsername("cheng");
    	return JSON.toJSONString(user);
    }
    
    public void setUserService(UserService userService) {
		this.userService = userService;
	}
}
